package com.qf.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author zdl
 * @date 2025/1/11
 */
public class Demo3 {
    public static void main(String[] args) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        //获取 方法
        Class<Animal> ac = Animal.class;
        Method method = ac.getMethod("eat", null);
        Animal animal = ac.newInstance();
        method.invoke(animal,null);

        Method method1 = ac.getMethod("eat", String.class);
        method1.invoke(animal,"王五");

        Method method2 = ac.getMethod("eat", String.class, int.class);
        method2.invoke(animal,"赵六",33);
    }
}
